var jsonList = {};
jsonList.state = 3;
var page = 1;
var rows = 10;
$(function (){
    //创建频道
    $(document).on("click",".re_pd", function () {
        $(this).parent().parent().remove();
    })
    //添加
    $(".zdy_add").on("click", function () {
        var pd_name = $(".pd_name").val();//自定义频道名称
        var qt_show = $(".qt_show").val();//是否前台显示
        var pd_sort = $(".pd_sort").val();//频道排序
        if (qt_show==1){
            qt_show=true;
        }else{
            qt_show =false;
        }
        if (pd_name==""){
            zeroModal.alert('请输入自定义频道名称');
        }
        if (pd_sort==""){
            zeroModal.alert('请输入自定义频道排序值');
        }
        var numCount = 0;
        var ids = '';
        $(".re_pd").each(function (index, key) {
            
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
        
        })
        ids = ids.substring(0, ids.length - 1);
        //console.log(ids, 555);
        if (numCount >= 1) {
            //进行下一步
            var json = {
                "cname": pd_name,
                "csort": pd_sort,
                "reveal": qt_show
            }
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要创建自定义频道吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/channel/diy/add?sids=" + ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        console.log(res, 333)
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('创建失败');
                        }
                    }
                })
            })
        } else {
            zeroModal.alert('请选择一条专题加入自定义频道');
        }
    })
    //移动
    $(document).on("click",".add_pd",function (){
        var result = $(this).parent().parent().prop("outerHTML");
        console.log(result);
       var r= $(result);
       r.find(".add_pd").html("移除频道");
        r.find(".add_pd").addClass("re_pd");
        r.find(".add_pd").removeClass("add_pd");
       console.log(r)
        $(".yiadd").append(r)
    })
    $(".btn_sqs").on('click', function () {
        var ztid = $(".ztid").val() || "";//专题id
        var zimc = $(".zt_name").val() || "";//专题名称
        if (ztid != "") {
            jsonList.id = ztid
        }
        if (zimc != "") {
            jsonList.title = zimc
        }
        getList();
    })
})
getList();
function getList() {
    var result = JSON.stringify(jsonList);
    $.ajax({
        url: baseNews + "/api/data/common/special/list?page=" + page + "&rows=" + rows,
        type: "post",
        headers: { 'Content-Type': 'application/json' },
        dataType: "json",
        data: result,
        success: function (res) {
            console.log(res, 666);
            if (res.code == 0) {
                var result = res.data;
                var list = result.list;
                console.log(list, 9999)
                var html = "";
                $("#page").paging({
                    pageNo: page,
                    totalPage: result.totalpage,
                    totalSize: result.totals,
                    callback: function (num) {
                        page = num;
                        getList();
                    }
                })
                $(".yfb_list").empty();
                $(list).each(function (index, key) {
                    var state = key.state;//文章的状态
                    var newState = "";//文章的
                    if (state == 0) {
                        newState = "";
                    }
                    if (state == 1) {
                        newState = "待审核";
                    }
                    if (state == 2) {
                        newState = "待发布";
                    }
                    if (state == 3) {
                        newState = "已发布";
                    }
                    if (state == 10) {
                        newState = "有更新";
                    }
                    if (state == -1) {
                        newState = "审核失败";
                    }
                    if (state == -2) {
                        newState = "撤销发布";
                    }
                    html +=`<tr>
							<th style="display:none">
							<input type="checkbox" class="arc_isc" oid="${key.id}">
							</th>
							<th>${key.title}</th>
							<th>${key.createtime}</th>
							<th>${key.updatetime}</th>
							<th>${key.rtime}</th>
							<th>${key.follow}</th>
							<th>${key.collect}</th>
                            <th>${key.articles}</th>
                            <th ><i class="addp add_pd" style="cursor: pointer;" oid="${key.id}">加入频道</i></th>
						</tr>`;
                })
                $(".yfb_list").append(html);
            }
        }

    })
    //分页

}